<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

	<section class="content-header">
		<h1>详情</h1>
		<ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">采购目录查询</a></li>
        </ol>
	</section>

	<section class="content">
		<div class=" box box-success">
			<div class="box-body">
				<div class="input">
					<div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                    <div class="textalign1">配送企业<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="psCompName" name="psCompName"  placeholder="配送企业/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
					<div class="textalign1"><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="prodComp" name="prodComp"  placeholder="<spring:message code="message.listForm.shengChanQiYe"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
					
				</div>
				<div class="input" >
					
                   <div class="textalign1">药品来源<spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <select class="textinput"  id="goodsSource" name="goodsSource">
                        <option value=""><spring:message code="message.select.option"/></option>
                        <c:forEach items="${list }" var="list">
                            <option value="${list.dicCode }">${list.dicName }</option>
                        </c:forEach>
                        </select>
                    </div>
					<div class="textalign1" >
					<button type="button" onclick="gridSerch()" class="btn btn-success btn-sm"  id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
				</div>
			</div>
			</div>
			
		</div>
		
		<table class="jqgrid" id="gridlist"></table>
		<div id="prowed2"></div>
		
		
		<div class=" box box-warning bottongroup" id="bottongroup">
			<%-- <label onclick="window.location.href='${ctx}/hospCatalog/toHospList.html'" class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></label> --%>
			<button id="delete" type="button" onclick="batchDelete()" class="btn btn-primary btn-sm">删 除</button>
			<a href="javascript:history.go(-1)" class="btn btn-danger btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
		</div>
 
	</section>
	
	<%@ include file="/WEB-INF/component/commonJS.jsp"%>
	<script type="text/javascript">
	//绑定回车
    $('#drugName,#drugCode,#prodComp,#bakDrugFlag,#isLongTimePlan,#psCompName').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectDicCompType').click();
        }
    });	
    $("#drugName").focus();//加载页面光标在第一个查询框内
	
	function batchDelete(){
		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
        if (rowIds.length <= 0) {
        	top.$.HN.message.alert("请选择要删除的目录！", "<spring:message code="message.HN.alert.type"/>", "warn");
            return;
        }
        var list = [];
        var areaIds = "";
        var areaNames = "";
        for (var i=0; i<rowIds.length; i++) {
            rowId = rowIds[i];
            var rowdata =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
            list.push({"goodsCode":rowdata.goodsCode});
		}
        $.HN.message.confirm("确定要删除所选目录吗？", '提示', '').on(function (e) {
            if (e) {
        $.post("${ctx}/hospCatalog/batchDelete.html", {
            "array" : json.jsonToString(list),"hospCode":"${hospInfo.hospCode}"
        }, function(result) {
            if (result.success) {
                $.alert(result.msg, "success");
                   $("#gridlist").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
            } else {
                $.alert(result.msg, "error");
            }
        }, "json");
            }
        });
    }
		
		
	   $(function () {
			jQuery("#gridlist").jqGrid({
			    url: "${ctx}/hospCatalog/getCatalogByHosp.html",
			    mtype: "POST",
			    postData:{"hospCode":"${hospInfo.hospCode}"},
			    datatype: "json",
			    autowidth: true,
			    //shrinkToFit:false,
			  //  height: 270,
			    colNames:[
			              'drugId',
						  '<spring:message code="message.jqGrid.cz"/>',
						  'compId',
						  '<spring:message code="message.model.peiSongQiYe"/>',
						  '<spring:message code="message.listForm.ZhongBiaoJia"/>',
						  '<spring:message code="message.listForm.ZhongBiaoJia"/>',
	                      '<spring:message code="message.listForm.ZhongBiaoHouLingShouJia"/>',
			              '<spring:message code="message.listForm.yaoPinBianMa"/>',
		                  '<spring:message code="message.listForm.tongYongMing"/>', 
		                  '<spring:message code="message.listForm.jiXing"/>',
		                  '<spring:message code="message.listForm.guiGe"/>',
		                  '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
		                  '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
		                  '<spring:message code="message.listForm.caiZhi"/>',
			              'prodCompId',
			              '<spring:message code="message.listForm.shengChanQiYe"/>',
						   '国药准字',
			              '<spring:message code="message.listForm.shangBianMa"/>',
			              '<spring:message code="message.lable.suoShuXiangMu"/>',
			              '<spring:message code="message.listForm.YaoPinFenLei"/>',
			              '<spring:message code="message.listForm.yaoPinLaiYuan"/>',
						  '药品类别',
					
			              '<spring:message code="message.listForm.BeiAnLeiXing"/>','',''
			              ],
			    colModel:[
			        {name: 'drugId',hidden:true, width: 20 , align:"center" ,sortable: false},
					{ name: 'oper', index: 'ship',width:50, align: "center" , sortable:false,
						formatter:function(val, options, row) {
							return "<a href=\"javascript:deleteHospcatalog('"+row.goodsCode+"','"+row.hospProCatId+"','"+row.drugName+"','"+row.hospCode+"')\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px 0px' class='opIcon' title='<spring:message code="message.button.delete"/>'></a>";
                    	} 
					},
					{name: 'compId',hidden:true, width: 20 , align:"center" ,sortable: false},
			        {name:'psCompName',index:'psCompName', width:180 , align:"center",sortable: false},
					{name:'proPrice',index:'proPrice', width:60 , align:"right",sortable: false,
                 	   formatter:function(cellvalue, options, row){
                           return formatAmount(cellvalue, options, row);
                       }},
                       
                    
			        {name:'proPriceLimit',index:'proPriceLimit', hidden:true,width:100 , align:"right",sortable: false},
			        {name:'retailPriceLimit',index:'retailPriceLimit', width:100 , align:"right",sortable: false},
			        {name:'drugCode',index:'drugCode', width:100, align:"center",sortable: false,hidden:true},
			        {name:'drugName',index:'drugName', width:180, sortable: false , align:"center"},
			        {name:'formName',index:'formName', width:100, align:"center",sortable: false},
			        {name:'specName',index:'specName', width:100 , align:"center",sortable: false},
			        {name:'factor',index:'factor', width:80, align:"center",sortable: false},
			        {name:'unit',index:'unit', width:80, align:"center",sortable: false},
			        {name:'materialName',index:'materialName', width:80, align:"center",sortable: false,hidden:true},
			        {name:'prodCompcode',hidden:true, width: 20 , align:"center" ,sortable: false},
			        {name:'prodCompname',index:'prodComp', width:210 , align:"center",sortable: false},
			        
			        {name:'drugMedicine',index:'drugMedicine',width:100 , align:"right",sortable: false},
			        {name:'goodsCode',index:'goods_code',  align:"center",hidden:true, width:120, sorttype:"date",sortable: false},
			        
			        {name:'projName',hidden:true, index:'projName', width:180 , align:"center",sortable: false},
			        {name:'drugCatName',index:'drugCatName', width:100 , align:"center",sortable: false,hidden:true},
			        {name:'goodsSourceName',index:'goodsSourceName', width:100 , align:"center",sortable: false},
					{name:'drugAttr',index:'drugAttr',sortable: false, width:80, align:"left",sorttype:false,
						formatter : function(val, opts, rowdata) {
							var str = "";
							if (val == 1) {
								str = "国家基本药物";
							} else if (val == 2) {
								str = "非基本药物";
							} else if (val == 3) {
								str = "省增补基本药物";
							} 
							return str;
						}
					},
			        {name:'isLongTimePlan',index:'isLongTimePlan', width:100 , align:"center",sortable: false,hidden:true,
                        formatter:function(cellvalue, options, row){
                        	var str = "";
                        	if (row.goodsSource == 5) {
                        		str = cellvalue == 1 ? "<spring:message code="message.listForm.ChangQiBeiAnLeiXing"/>" : "<spring:message code="message.listForm.LinShiBeiAn"/>";
                        	}
                        	return str;
                        }
                    },
					{name:'czbs',hidden:true, width:180 , align:"center",sortable: false},
					{name:'hospProCatId',hidden:true, width:180 , align:"center",sortable: false}
			    ],
			     rowNum: 20,
			     rowList: [10, 20, 50,100],
			     rownumbers: true,
			     multiselect: true,
			     pager: "#prowed2",
			     viewrecords: true,
			     gridComplete:function(){
					//序号列宽度自适应（参数为jqgridID）
					autoRNWidth("gridlist");
					//数据只有一条时默认选中（参数为jqgridID）
					selectByOneData("gridlist");
	                },
			     caption: "${hospInfo.hospName}",
			     editurl:"proPlanItemListHis.jsp",
			     jsonReader: {
			         repeatitems: false,
			         id: "hospProCatId"
			     }
			});
			     
			jQuery("#gridlist").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
			$(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight",create());
		});
		
	   
		function gridSerch() {
		    var goodsCode = $.trim($("#goodsCode").val());
		    var drugCode = $.trim($("#drugCode").val());
		    var drugName = $.trim($("#drugName").val());
		    var formName = $.trim($("#formName").val());
		    var specName = $.trim($("#specName").val());
		    var prodComp = $.trim($("#prodComp").val());
		    var isLongTimePlan = $("#isLongTimePlan").val();
		    var psCompName = $.trim($("#psCompName").val());
			var goodsSource = $.trim($("#goodsSource").val());
		    $("#gridlist").jqGrid('setGridParam',{  
		        datatype:'json',
		        postData:{"goodsCode":goodsCode,
		                "drugCode":drugCode,
		                "drugName":drugName,
		                "formName":formName,
		                "specName":specName,
		                "psCompName":psCompName,
		                "prodComp":prodComp,
						"goodsSource":goodsSource,
		                "isLongTimePlan":isLongTimePlan
		        },
		        page:1
		    }).trigger("reloadGrid"); //重新载入  
		}
		
		//批量保存
		function batchSaveGoodsSelect(){
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
            	top.$.HN.message.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.model.peiSongQiYe"/><spring:message code="message.lable.de"/><spring:message code="message.listForm.shang"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
            }
            var list = [];
            var compName = "";
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
				if(rowdata.czbs != 1) {
					top.$.HN.message.alert("您选择的"+rowdata.drugName+"未更换配送企业！", "<spring:message code="message.HN.alert.type"/>", "warn");
                    return;
				}
               
                if(3>i){
            		compName+=rowdata.psCompName+"<br/>"
                	if(2==i){
                		compName+="...";
                	}
                }
                
            }
            
            $.HN.message.confirm("确定加入以下配送企业吗？<br/>"+compName+"", '', '').on(function (e) {
                if (e) {
                	$("#jrml").attr("disabled", true); 
                    var list = [];
                    for (var i=0; i<rowIds.length; i++) {
                        rowId = rowIds[i];
                        var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                        list.push({"goodsCode":rowdata.goodsCode,"drugName":rowdata.drugName,"proPrice":rowdata.proPrice,"proLimitPrice":rowdata.proPriceLimit,"delCompCode":rowdata.compId,"hospProCatId":rowdata.hospProCatId});
                    }
                    $.post("${ctx}/purHospCatalog/batchModifyCgmlZx.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                        	top.$.HN.message.alert("成功更换"+list.length+"个配送企业", "<spring:message code="message.HN.alert.type"/>", "success");
                        	gridSerch($("#gridlist").getGridParam("page"));
                        	$("#jrml").attr("disabled", false); 
                        } else {
                            top.$.HN.message.alert(result.msg, "<spring:message code="message.HN.alert.type"/>", "error");
                            $("#jrml").attr("disabled", false); 
                        }
                    }, "json")
                }
            });
        }
		 
		 //回调
		function operResult(val){
	        var strs = new Array();
	        strs = val.split("|$");
	        if (val.length>0) {
	        	var rowdata = $("#gridlist").jqGrid('getRowData', strs[1]);
	        	if(rowdata.compId == strs[2]){
	        		$("#gridlist").jqGrid('setCell',strs[1],'czbs', 0);
	        	}else{
	        		$("#gridlist").jqGrid('setCell',strs[1],'czbs', 1);
	        	}
	            $("#gridlist").jqGrid('setCell',strs[1],'compId',strs[2]);
	            $("#gridlist").jqGrid('setCell',strs[1],'psCompName',strs[3]);
			}	
					
	    }
		
		//删除采购目录
		function deleteHospcatalog(goodsCode,hospProCatId,drugName,hospCode) {
			$.HN.message.confirm("确定删除该商品吗？<br/>"+drugName+"", '', '').on(function (e) {
                if (e) {
                	$("#jrml").attr("disabled", true); 
                    var list = [];
                    list.push({"goodsCode":goodsCode,"hospProCatId":hospProCatId,"hospCode":hospCode});
                    $.post("${ctx}/purHospCatalog/deleteHospcatalog.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                        	top.$.HN.message.alert("成功删除"+list.length+"个商品", "<spring:message code="message.HN.alert.type"/>", "success");
                        	gridSerch($("#gridlist").getGridParam("page"));
                        	$("#jrml").attr("disabled", false); 
                        } else {
                            top.$.HN.message.alert(result.msg, "<spring:message code="message.HN.alert.type"/>", "error");
                            $("#jrml").attr("disabled", false); 
                        }
                    }, "json")
                }
            });
		}
</script>
</body>
</html>